package com.atguigu.gmall.mq.controller;


import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.common.service.RabbitService;
import com.atguigu.gmall.mq.config.DeadLetterMqConfig;
import com.atguigu.gmall.mq.config.DelayedMqConfig;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/api/mq")
public class MqController {

    @Resource
    private RabbitService rabbitService;

    //发送普通消息
    @GetMapping("/sendMessage1")
    public Result sendMessage1(String message){
        System.out.println("发送的消息1："+message);
        rabbitService.sendMessage("exchange1","routingKey1",message);
        return Result.ok();
    }

    //发送普通消息
    @GetMapping("/sendMessage2")
    public Result sendMessage2(String message){
        System.out.println("发送的消息2："+message);
        rabbitService.sendMessage("exchange2","routingKey2",message);
        return Result.ok();
    }

    //发送死信消息
    @GetMapping("/sendDeadLetterMessage")
    public Result sendDeadLetterMessage(String message){
        System.out.println("发送的死信消息："+message);
        rabbitService.sendDeadLetterMessage(DeadLetterMqConfig.exchange_dead,
                DeadLetterMqConfig.routing_dead_1,message,8);
        return Result.ok();
    }

    //发送延迟消息(基于插件)
    @GetMapping("/sendDelayMessage")
    public Result sendDelayMessage(String message){
        System.out.println("发送的延迟消息："+message);
        rabbitService.sendDelayMessage(DelayedMqConfig.exchange_delay,DelayedMqConfig.routing_delay,message,8);
        return Result.ok();
    }
}
